package com.sparrow.manage.comment;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface CommentDao extends JpaRepository<Comment, String> {

    @Query(value = "select * from tb_comment where type_ = ?1 order by create_time is null, create_time desc limit ?2", nativeQuery = true)
    List<Comment> queryByType(Integer code, Integer count);

    /**
     * 删除历史留言数据, 只保留1000条留言
     */
    @Modifying
    @Query(nativeQuery =  true, value = "DELETE from tb_comment where id_ not in (SELECT id_ FROM tb_comment order by create_time DESC limit 1000)")
    @Transactional
    void deleteHistory();
}
